<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card>
        <el-tabs>
          <el-tab-pane label="登录账户设置">
            <!-- 放置表单 -->
            <el-form ref="userInfoForm" label-width="120px" style="margin-left: 120px; margin-top:30px" :model="userinfo" :rules="rules">
              <el-form-item label="姓名:" prop="username">
                <el-input v-model="userinfo.username" style="width:300px" />
              </el-form-item>
              <el-form-item label="密码:" prop="password">
                <el-input v-model="userinfo.password" style="width:300px" type="password" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="submitFn">更新</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="个人详情">
            <userInfo />
          </el-tab-pane>
          <el-tab-pane label="岗位信息">

            <jobInfo />
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
  </div>
</template>

<script>
// 获取用户的用户名和密码
import { getdetdilsapi, saveUserDetailById } from '@/api/user'
import jobInfo from '@/views/employees/components/job-info.vue'
import userInfo from '@/views/employees/components/user-info.vue'
export default {
  components: {
    jobInfo, userInfo
  },
  data() {
    return {
      userid: this.$route.params.id,
      userinfo: {
        username: '',
        password: ''
      },
      // 校验规则
      rules: {
        username: [
          { required: true, message: '该项不能为空', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '该项不能为空', trigger: 'blur' },
          { min: 6, max: 12, message: '密码在6-12位之间', trigger: 'blur' }
        ]
      }

    }
  },
  // 点击查看后通过路由传过来的id,调用获取用户详情接口
  async created() {
    this.userinfo = {
      ...await getdetdilsapi(this.userid),
      password: ''
    }
  },
  methods: {
    async submitFn() {
      // 先校验表单
      await this.$refs.userInfoForm.validate()
      //   校验通过就发请求到后台
      await saveUserDetailById(this.userinfo)
      //   修改成功后提示用户
      this.$message.success('修改成功')
    }
  }

}
</script>

<style>

</style>
